package com.jd.aop;


import com.jd.common.AjaxResult;
import com.jd.enums.ResultEnums;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by Administrator on 2017/9/22/022.
 */
@ControllerAdvice//对controller进行增强
@Component
public class GobalExceptionHandler {

    @ExceptionHandler(value={Exception.class})//捕获所有的异常信息
    @ResponseBody//将异常信息返回
    public AjaxResult handler(Exception e){//spring会注入一个Exception对象
        return new AjaxResult(ResultEnums.ERROR.getCode(),ResultEnums.ERROR.getMsg(),e.getMessage());
    }
}
